/**
 * 
 */
package fr.umlv.m2.ig.model;


/**
 * This class defines a train object.
 * 
 * @author Gambouele Bertrand.
 * @author VIRAVOUT Alexandre.
 */
public class Train {

	/**
	 * Train id.
	 */
	private final String id;

	/**
	 * Train line.
	 */
	private final String line;

	/**
	 * Train origin.
	 */
	private String origin;
	
	/**
	 * Train destination.
	 */
	private String destination;
	
	/**
	 * X coordinate.
	 */
	private double positionX;
	
	/**
	 * Y coordinates.
	 */
	private double positionY;
	
	/**
	 * Next station name.
	 */
	private String nextStation;

	/**
	 * Current station name.
	 */
	private String currentStation;

	/**
	 * Number of remaining moves.
	 */
	private int remainingMoves;
	
	/**
	 * X move step.
	 */
	private double moveStepX;
	
	/**
	 * Y move step.
	 */
	private double moveStepY;

	/**
	 * Waiting time.
	 */
	private int waitingTime;
	
	/**
	 * Creates a new {@code Train} object.
	 * 
	 * @param id train id.
	 * @param line train line.
	 * @param startStation train start station.
	 * @param destination1 train destination.
	 * @param destination2 train nextDestination
	 */
	public Train(final String id, final String line, String startStation, String destination1, String destination2) {
		this.id = id;
		this.line = line;
		
		this.currentStation = startStation;
		this.destination = destination1;
		this.origin = destination2;
	}
	
	/**
	 * Reverse the train itinerary. Origin becomes destination and destination
	 * becomes origin.
	 */
	void reverseItinerary() {
		String tmp = this.origin;
		
		this.origin = this.destination;
		this.destination = tmp;
	}
	
	/**
	 * Returns the train id.
	 * 
	 * @return train id.
	 */
	public String getId() {
		return this.id;
	}
	
	/**
	 * Returns the train line.
	 * 
	 * @return train line.
	 */
	public String getLine() {
		return this.line;
	}
	
	/**
	 * Sets the next station for this train.
	 * 
	 * @param nextStation next station.
	 */
	void setNextStation(final String nextStation) {
		this.nextStation = nextStation;
	}
	
	/**
	 * Returns the next station for this train.
	 * 
	 * @return next station.
	 */
	public String getNextStation() {
		return this.nextStation;
	}
	
	/**
	 * Sets the current station for this train.
	 * 
	 * @param currentStation current station.
	 */
	void setCurrentStation(final String currentStation) {
		this.currentStation = currentStation;
	}
	
	/**
	 * Returns the current 
	 * @return
	 */
	public String getCurrentStation() {
		return this.currentStation;
	}
	
	/**
	 * Moves the train.
	 * @return
	 */
	boolean move() {
		if (this.waitingTime > 0) {
			waitingTime--;

			return false;
		}

		if (remainingMoves > 0) {
			positionX += moveStepX;
			positionY += moveStepY;
			remainingMoves--;

			return true;
		}
		
		return false;
	}
	
	/**
	 * Sets the number of remaining moves for this train.
	 * 
	 * @param remainingMoves number of remaining moves.
	 */
	void setRemainingMoves(int remainingMoves) {
		this.remainingMoves = remainingMoves;
	}
	
	/**
	 * Returns the train X coordinate.
	 * 
	 * @return train X coordinate.
	 */
	public double getPositionX() {
		return this.positionX;
	}
	
	/**
	 * Returns the train Y coordinate.
	 * 
	 * @return train Y coordinate.
	 */
	public double getPositionY() {
		return this.positionY;
	}

	/**
	 * Sets the train coordinates.
	 * 
	 * @param posX X coordinate.
	 * @param posY Y coordinate.
	 */
	void setPosition(double posX, double posY) {
		this.positionX = posX;
		this.positionY = posY;
	}
	
	/**
	 * Returns the train destination.
	 * 
	 * @return train destination.
	 */
	public String getDestination() {
		return this.destination;
	}

	/**
	 * Sets the train waiting time.
	 * 
	 * @param waitingTime Train waiting time.
	 */
	void setWaitingTime(int waitingTime) {
		this.waitingTime = waitingTime;
	}

	/**
	 * Sets the X move step.
	 * 
	 * @param stepX X move step.
	 */
	void setStepX(double stepX) {
		this.moveStepX = stepX;
	}

	/**
	 * Sets the Y move step.
	 * 
	 * @param stepY Y move step.
	 */
	void setStepY(double stepY) {
		this.moveStepY = stepY;
	}

	/**
	 * Returns the number of remaining moves.
	 * 
	 * @return Number of remaining moves.
	 */
	public int getRemainingMoves() {
		return this.remainingMoves;
	}

	/**
	 * Returns the trains origin.
	 * 
	 * @return the train origin.
	 */
	public String getOrigin() {
		return this.origin;
	}

	/**
	 * Returns the Y move step.
	 * 
	 * @return stepY Y move step.
	 */
	public double getMoveStepY() {
		return this.moveStepY;
	}

	/**
	 * Returns the X move step.
	 * 
	 * @return stepX X move step.
	 */
	public double getMoveStepX() {
		return this.moveStepX;
	}

	/**
	 * Returns the train waiting time.
	 * 
	 * @return train waiting time.
	 */
	public int getWaitingTime() {
		return this.waitingTime;
	}
}
